package com.alog.storage.ui.dialog;

import com.alog.storage.R;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.widget.TextView;

/**
 * 加载对话框
 */
public class LoadingDialog extends Dialog {
    public static enum ProgressStyle {
        DEFAULT,
        LOTTERY_COMMON,
        LOTTERY_OVERLAY
    }

    public LoadingDialog(Context context) {
        super(context);
    }

    protected LoadingDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public LoadingDialog(Context context, int theme) {
        super(context, theme);
    }

    public static LoadingDialog createDialog(Context context, ProgressStyle style) {
        return createDialog(context, style, true);
    }

    public static LoadingDialog createDialog(Context context, ProgressStyle style, boolean cancelable) {
        LoadingDialog instance = null;
        switch (style) {
            case DEFAULT:
                instance = new LoadingDialog(context);
                break;

            case LOTTERY_COMMON:
                instance = new LoadingDialog(context, R.style.CommonProgressDialog);
                break;

            case LOTTERY_OVERLAY:
                instance = new LoadingDialog(context, R.style.CommonProgressDialog);
                break;

            default:
                instance = new LoadingDialog(context);
                break;
        }
        instance.setContentView(R.layout.progress_dialog);
        instance.getWindow().getAttributes().gravity = Gravity.CENTER;
        instance.setCancelable(cancelable);
        return instance;
    }

    public void setLoadInfo(String information) {
        TextView loadInfoTxt = (TextView) findViewById(R.id.dialog_load_info);
        if (loadInfoTxt != null) {
            loadInfoTxt.setText(information);
        }
    }
}
